home *** CD-ROM | disk | FTP | other *** search
/ Chip 2011 November / CHIP_2011_11.iso / Programy / Inne / Gry / Carnage_Contest / scripts / CC Original / weapons / Drill Rocket.lua < prev    next >
Text File  |  2010-09-22  |  6KB  |  171 lines

  1. --------------------------------------------------------------------------------
  2. -- Weapon Drill Rocket Launcher + Projectile (Drill) Rocket
  3. -- Original Carnage Contest Weapon
  4. -- Script by DC, August 2009, www.UnrealSoftware.de
  5. --------------------------------------------------------------------------------
  6.  
  7. -- Setup Tables
  8. if cc==nil then cc={} end
  9. cc.drillrocket={}
  10. cc.drillrocket.rocket={}
  11.  
  12. -- Load & Prepare Ressources
  13. cc.drillrocket.gfx_wpn=loadgfx("weapons/launcher.bmp")                    -- Weapon Image
  14. setmidhandle(cc.drillrocket.gfx_wpn)
  15. cc.drillrocket.gfx_pro=loadgfx("weapons/drillrocket.bmp")                -- Projectile Image
  16. setmidhandle(cc.drillrocket.gfx_pro)
  17. cc.drillrocket.sfx_attack=loadsfx("rocketrelease.wav")                    -- Attack Sound
  18. cc.drillrocket.sfx_drill=loadsfx("drill.ogg")                            -- Drill Sound
  19.  
  20. --------------------------------------------------------------------------------
  21. -- Weapon: Drill Rocket Launcher
  22. --------------------------------------------------------------------------------
  23.  
  24. cc.drillrocket.id=addweapon("cc.drillrocket","Drill Rocket",cc.drillrocket.gfx_pro,0,2)    -- Add Weapon (0 uses, first in round 2)
  25.  
  26. function cc.drillrocket.draw()                                            -- Draw
  27.     setblend(blend_alpha)
  28.     setalpha(1)
  29.     setcolor(120,120,100)
  30.     drawinhand(cc.drillrocket.gfx_wpn,6,0)
  31.     -- HUD chargebar
  32.     if weapon_charge>0 and weapon_shots==0 then
  33.         hudchargebar(weapon_charge,100)
  34.     end
  35.     -- HUD Crosshair
  36.     if weapon_shots==0 then
  37.         hudcrosshair(6,3)
  38.     end
  39. end
  40.  
  41. function cc.drillrocket.attack(attack)                                    -- Attack
  42.     if (weapon_shots<=0) then
  43.         -- Charge
  44.         if (attack==1) then
  45.             weapon_charge=weapon_charge+1                            -- Increase charge
  46.         end
  47.         -- Fire a projectile (on release/full charge)
  48.         if (attack==0 and weapon_charge>0) or (weapon_charge>=100) then
  49.             -- No more weapon switching!
  50.             useweapon(0)
  51.             playsound(cc.drillrocket.sfx_attack)
  52.             weapon_shots=weapon_shots+1
  53.             id=createprojectile(cc.drillrocket.rocket.id)
  54.             projectiles[id]={}
  55.             -- Ignore collision with current player at beginning
  56.             projectiles[id].ignore=playercurrent()
  57.             -- Set initial position of projectile
  58.             projectiles[id].x=getplayerx(0)+(6*getplayerdirection(0))+math.sin(math.rad(getplayerrotation(0)))*10.0
  59.             projectiles[id].y=getplayery(0)+3-math.cos(math.rad(getplayerrotation(0)))*10.0
  60.             -- Timer
  61.             projectiles[id].timer=0
  62.             -- Initial movement
  63.             projectiles[id].sx=math.sin(math.rad(getplayerrotation(0)))*20
  64.             projectiles[id].sy=-math.cos(math.rad(getplayerrotation(0)))*20
  65.             projectiles[id].x=projectiles[id].x-projectiles[id].sx
  66.             projectiles[id].y=projectiles[id].y-projectiles[id].sy
  67.             cc.drillrocket.rocket.move(id,0)
  68.             -- Set speed of projectile
  69.             projectiles[id].sx=math.sin(math.rad(getplayerrotation(0)))*(weapon_charge/100.0)*6.0
  70.             projectiles[id].sy=-math.cos(math.rad(getplayerrotation(0)))*(weapon_charge/100.0)*6.0
  71.             -- Effects
  72.             recoil(2)
  73.             -- End Turn
  74.             endturn()
  75.         end
  76.     end
  77. end
  78.  
  79. --------------------------------------------------------------------------------
  80. -- Projectile: (Drill) Rocket
  81. --------------------------------------------------------------------------------
  82.  
  83. cc.drillrocket.rocket.id=addprojectile("cc.drillrocket.rocket")        -- Add Projectile
  84.  
  85. function cc.drillrocket.rocket.draw(id)                                -- Draw
  86.     -- Setup draw mode
  87.     setblend(blend_alpha)
  88.     setalpha(1)
  89.     setcolor(255,255,255)
  90.     setscale(1,1)
  91.     -- Calculate projectile rotation
  92.     setrotation(math.deg(math.atan2(projectiles[id].sx,-projectiles[id].sy)))
  93.     -- Draw projectile
  94.     drawimage(cc.drillrocket.gfx_pro,projectiles[id].x,projectiles[id].y)
  95.     -- Draw Arrow if out of Screen
  96.     outofscreenarrow(projectiles[id].x,projectiles[id].y)
  97. end
  98.  
  99. function cc.drillrocket.rocket.update(id)                            -- Update
  100.     -- Move
  101.     cc.drillrocket.rocket.move(id,1)
  102. end
  103.  
  104. function cc.drillrocket.rocket.move(id,fx)
  105.     rot=math.deg(math.atan2(projectiles[id].sx,-projectiles[id].sy))
  106.     -- Particle Tail
  107.     if (fx==1) then
  108.         particle(p_smoke,projectiles[id].x-math.sin(math.rad(rot))*7,projectiles[id].y+math.cos(math.rad(rot))*7)
  109.         particlespeed(math.random(-2,2)*0.1,math.random(-2,2)*0.1)
  110.         particlefadealpha(0.01)
  111.         particle(p_lightpuff,projectiles[id].x-math.sin(math.rad(rot))*6,projectiles[id].y+math.cos(math.rad(rot))*6)
  112.         particlefadealpha(0.04)
  113.     end
  114.     -- Wind + Gravity influence on speed
  115.     projectiles[id].sx=projectiles[id].sx+getwind()*0.3
  116.     projectiles[id].sy=projectiles[id].sy+getgravity()
  117.     -- Move (in substep loop for optimal collision precision)
  118.     msubt=math.ceil(math.max(math.abs(projectiles[id].sx),math.abs(projectiles[id].sy))/4)
  119.     msubx=projectiles[id].sx/msubt
  120.     msuby=projectiles[id].sy/msubt
  121.     for i=1,msubt,1 do
  122.         projectiles[id].x=projectiles[id].x+msubx
  123.         projectiles[id].y=projectiles[id].y+msuby
  124.         -- Collision
  125.         if collision(col5x5,projectiles[id].x+math.sin(math.rad(rot))*3,projectiles[id].y-math.cos(math.rad(rot))*3)==1 then
  126.             if terraincollision()==1 or objectcollision()>0 or playercollision()~=projectiles[id].ignore then
  127.                 playsound(cc.drillrocket.sfx_drill)
  128.                 -- Cause Player damage
  129.                 if playercollision()~=0 and fx==1 then
  130.                     projectiles[id].timer=15
  131.                 end
  132.                 -- Cause Object damage
  133.                 if objectcollision()>0 and fx==1 then
  134.                     projectiles[id].timer=15
  135.                 end
  136.                 -- Destroy terrain
  137.                 terrainexplosion(projectiles[id].x,projectiles[id].y,16,2)
  138.                 -- Timer / Free
  139.                 projectiles[id].timer=projectiles[id].timer+1
  140.                 if projectiles[id].timer>=15 then
  141.                     -- Explode
  142.                     arealdamage(projectiles[id].x,projectiles[id].y,50,50)
  143.                     terrainexplosion(projectiles[id].x,projectiles[id].y,25,1)
  144.                     -- Crater
  145.                     grey=math.random(0,40)
  146.                     if math.random(0,1)==1 then
  147.                         terrainalphaimage(gfx_crater100,projectiles[id].x,projectiles[id].y,math.random(6,9)*0.1,grey,grey,grey)
  148.                     else
  149.                         terrainalphaimage(gfx_crater125,projectiles[id].x,projectiles[id].y,math.random(6,9)*0.1,grey,grey,grey)
  150.                     end
  151.                     -- Free
  152.                     freeprojectile(id)
  153.                     break
  154.                 end
  155.             end
  156.         elseif (fx==1) then
  157.             projectiles[id].ignore=0
  158.         end
  159.         -- Water
  160.         if (projectiles[id].y)>getwatery()+5 then
  161.             -- Effects
  162.             particle(p_waterhit,projectiles[id].x,projectiles[id].y)
  163.             playsound(sfx_hitwater1)
  164.             -- Free projectile
  165.             freeprojectile(id)
  166.             break
  167.         end
  168.     end
  169.     -- Scroll to projectile
  170.     scroll(projectiles[id].x,projectiles[id].y)
  171. end